package com.caine.disr;

import com.caine.disr.entity.RingEvent;
import com.lmax.disruptor.RingBuffer;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
public class DisrApplication implements CommandLineRunner {

    static List<RingEvent> list = new ArrayList<>(100000);

    public static void main(String[] args) {
        SpringApplication.run(DisrApplication.class, args);
    }

    static{
        RingEvent event = null;
        for(int i=1;i<=1000000;i++) {
            event = new RingEvent();
            event.setId(i).setMsg("测试"+i);
            list.add(event);
        }
    }

    @Autowired
    private RingBuffer<RingEvent> ringBuffer;

    @Override
    public void run(String... args) throws Exception {
        ringBuffer.publishEvents((event, sequence, arg0) -> BeanUtils.copyProperties(arg0,event,RingEvent.class), list.toArray());
    }
}
